// Fill out your copyright notice in the Description page of Project Settings.


#include "MyHUDInterface.h"
#include "UObject/ConstructorHelpers.h"
#include "Blueprint/UserWidget.h"
#include "Animation/WidgetAnimation.h"
#include "Kismet/GameplayStatics.h"
#include "RPG_CppCharacter.h"
#include "TimerManager.h"

void AMyHUDInterface::PopMessageOnScreen(FString MessageText) {

	//PopMessage->PlayAnimation();
	PopMessageText=MessageText;
	TSubclassOf<UUserWidget>WidgetClass2 = LoadClass<UUserWidget>(nullptr, TEXT("/Game/ThirdPersonCPP/Blueprints/PopMessage.PopMessage_C"));
	if (WidgetClass2)
	{
		UE_LOG(LogTemp, Warning, TEXT("LoadClass PopMessage Success"));
		FTimerHandle popTimerHandle;
		PopMessage = CreateWidget<UUserWidget>(GetWorld(), WidgetClass2);
		PopMessage->AddToViewport();
		auto Lambda1 = [this, &popTimerHandle]() mutable {
			GetWorldTimerManager().ClearTimer(popTimerHandle);
			PopMessage->RemoveFromParent();
		};
		FTimerDelegate TimerCallback = FTimerDelegate::CreateLambda(Lambda1);
		GetWorldTimerManager().SetTimer(popTimerHandle, TimerCallback, 2.5, false);
		
	}
}

void AMyHUDInterface::BeginPlay()
{
	Super::BeginPlay();
	TSubclassOf<UUserWidget>CharacterSelect = LoadClass<UUserWidget>(nullptr, TEXT("/Game/ThirdPersonCPP/Blueprints/CharacterSelect.CharacterSelect_C"));
	if (CharacterSelect)
	{
		UE_LOG(LogTemp, Warning, TEXT("LoadClass MyHUD Success"));
		MyHUD = CreateWidget<UUserWidget>(GetWorld(), CharacterSelect);
		MyHUD->AddToViewport();
	}
	/*TSubclassOf<UUserWidget>WidgetClass1 = LoadClass<UUserWidget>(nullptr, TEXT("/Game/ThirdPersonCPP/Blueprints/MyHUD.MyHUD_C"));
	if (WidgetClass1)
	{
		UE_LOG(LogTemp, Warning, TEXT("LoadClass MyHUD Success"));
		MyHUD = CreateWidget<UUserWidget>(GetWorld(), WidgetClass1);
		MyHUD->AddToViewport();
	}*/


}
